'use strict';
const mongoose = require('mongoose');
const config = require('../config/config.unittest.js')({});
const fs = require('fs');
const readline = require('readline');
const moment = require('moment');

let ParserBetter = require('../app/utils/rss/parser');
let parserBetter = new ParserBetter({timeout: 10000});

const UserModel = require('../app/model/User')({
  mongoose,
});
const TopicModel = require('../app/model/Topic')({
  mongoose,
});

mongoose.connect(config.mongoose.url, config.mongoose.options, function (err) {
  if (err) {
    console.error('connect to %s error: ', config.mongoose, err.message);
    process.exit(1);
  }
});

async function main() {

  const topics = await TopicModel.find({author_name: '凤凰新闻'});

  for (let i = 0; i < topics.length; i++) {
    console.log(i, topics.length);
    let topic = topics[i];
    if (topic.pic) {
      topic.pic = topic.pic.replace(/(.+d.ifengimg.com\/)(.+?)(\/x0.ifengimg.com.+)/, '$1w600_h337_q90_webp$3');
      await topic.save();
    }
  }


  process.exit(0);
}

main();

